<template>
  <div>
    <h2 style="text-align: center">中标信息</h2>
    <el-row>
      <el-col :span="8">
        标题：
        <el-input size="large" style="width: 200px;" v-model="queryObj.title" placeholder="请输入标题" clearable/>
      </el-col>

      <el-col :span="8">
        合同号：
        <el-input size="large" style="width: 200px;" v-model="queryObj.pact" placeholder="请输入合同号" clearable/>
      </el-col>


      <el-col :span="8">
        <el-button type="primary" @click="findConfirm(1)">搜索</el-button>
      </el-col>
    </el-row>

    <el-table :data="confirmList"  stripe height="400" style="width: 100%;margin-top: 20px;" >
      <el-table-column label="合同号" prop="pact"/>
      <el-table-column label="标题" prop="title"/>
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-badge :hidden="scope.row.readStatus===1" value="未读" class="item">
            <el-button size="default" type="primary" @click="findById(scope.row.id),showFindById=true">
              查看详情
            </el-button>
          </el-badge>
        </template>
      </el-table-column>
    </el-table>

    <el-dialog v-model="showFindById" :title="confirmObj.title" width="70%"  center>
      <div v-html="confirmObj.info" style="height:300px;border: black 1px solid"></div>
      <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="addOrder()">添加订单</el-button>
        <el-button @click="showFindById = false">取消</el-button>

      </span>
      </template>
    </el-dialog>

    <el-pagination
        v-model:current-page="currentPage"
        v-model:page-size="pageSize"
        background
        layout="prev, pager, next, jumper"
        :total="total"
        @current-change="findConfirm"
    />
  </div>
</template>

<script>
import axios from "axios";
import {ElMessage} from "element-plus";

export default {
  data() {
    return {
      confirmList: [],
      total: 0,
      currentPage: 1,
      pageSize: 6,
      queryObj: {},
      confirmObj: {},
      showFindById: false,
    }
  },
  methods: {
    findConfirm(pageNO) {
      this.currentPage = pageNO;
      this.queryObj.pageNO = pageNO
      axios.get("/project/biddConfirm/cutByItem", {params: this.queryObj})
          .then(resp => {
            let obj = resp.data;
            if (obj.success) {
              this.confirmList = obj.data.records;
              console.log(obj.data.records)
              this.total = obj.data.total;
              this.pageSize = obj.data.size
            }
          })
    },
    findById(id) {
      axios.get("/project/biddConfirm/findById", {params: {id}})
          .then(resp => {
            let obj = resp.data;
            if (obj.success) {
              this.confirmObj = obj.data
              console.log(obj.data)
              this.findConfirm(this.currentPage)
            }
          })
    }, addOrder() {
      axios.get("/project/order/add", {params: {pact: this.confirmObj.pact}}).then(resp => {
        let info = resp.data
        if (info.success) {
          ElMessage.success("添加成功")
          this.$router.push("/order")
        } else {
          ElMessage.error(info.errorMsg)
        }
      })
    }
  }, created() {
    this.findConfirm(1)
  }
}
</script>

<style scoped>
.item {
  margin-top: 10px;
  margin-right: 40px;
}
</style>